#include "Scribe.h"


  Scribe::Scribe() {
      READER_WRITER.close(); 
  };
  
  Scribe::~Scribe() {
      READER_WRITER.close();
  };

  void Scribe::readfile(vector<string>& book_contents, const char* filename) {
       string temp_string;
       READER_WRITER.open(filename);
       if(!READER_WRITER.good()){
        // cout<<"Cannot Open File for Reading!!!!"<<endl;
         //  exit(1);
           FileException e("CANNOT OPEN FILE FOR READING!!!!");
           e.setfilename(filename);
           throw(e);  
       }
           
       while(!READER_WRITER.eof()){
           getline(READER_WRITER, temp_string);
    //       cout<<temp_string<<endl; //Debug Line Remove when done
           book_contents.push_back(temp_string);
       }
       READER_WRITER.close();
          
  };
  
  void Scribe::writefile(vector<string>& book_contents, const char* filename) {
      int counter =0;
      READER_WRITER.open(filename, ios::out | ios::app);
      if(!READER_WRITER.good()){
      //    cout<<"Cannot Open File for Writing!!!!"<<endl;
      //    exit(1);
           FileException e("CANNOT OPEN FILE FOR WRITING!!!!");
           throw(e); 
      }

      while(book_contents.size()>counter) {
          READER_WRITER<<book_contents.at(counter);
          READER_WRITER<<endl;
          counter++;
      }
      
      READER_WRITER.close();
  }

    

